﻿<?php include_once("connection.php"); // the connection to the database ?>
<div style="overflow:hidden; margin:1em;">
<h1>Update</h1>
<?php if($_GET['submitted']) { 
	
	$newCategory = mysql_query("UPDATE category SET cat_ten = '".$_POST['cat_ten']." && cat_mota='".$_POST['cat_mota']."' WHERE cat_id = ".$_POST['cat_id']) or die(mysql_error());
	?>
	<script type="text/javascript">	
		$(document).ready(function(){
			$.nyroModalRemove();
		});
	</script>	
	<?php
	
} else { 

// extract the max order number: the new category will have this order number + 1
$rsCategoryName = mysql_query("SELECT * FROM category WHERE cat_id = ".$_GET['cat_id']) or die(mysql_error());
$results = mysql_fetch_array($rsCategoryName);
$cat_ten = $results['cat_ten'];
$cat_mota = $results['cat_mota'];
  
?>

<form method="POST" action="<?php echo $_SERVER["PHP_SELF"]."?submitted=true" ?>" name="modify" id="modify" class="nyroModal">
	<label for="category_name"></label>
	<input type="text" value="<?php echo $cat_ten ?>" name="cat_ten" id="cat_ten" />
	<input type="text" value="<?php echo $cat_mota ?>" name="cat_mota" id="cat_mota" />
	<input type="hidden" value="<?php echo $_GET['cat_id'] ?>" name="cat_id" id="cat_id" />
	<input type="submit" value="Modify" id="form_submit" />
</form>
<script type="text/javascript">	
	$(document).ready(function(){
		$("#form_submit").click(function(e){
			e.preventDefault();
			if ( $("#category_name").val() != "" ) $("#modify").submit();
			else alert("Hãy nhập tên category ");
		});
	});
</script>	 
<?php } ?>
</div>